﻿using System.ComponentModel.Composition;
using System.Diagnostics;
using SMSManager.Commn.Interfaces;

namespace SMSManager.Data
{
	// This class allows you to handle specific events on the settings class:
	//  The SettingChanging event is raised before a setting's value is changed.
	//  The PropertyChanged event is raised after a setting's value is changed.
	//  The SettingsLoaded event is raised after the setting values are loaded.
	//  The SettingsSaving event is raised before the setting values are saved.

	[PartCreationPolicy(CreationPolicy.Shared)]
	internal sealed partial class SMSSettings : ISMSSettings
	{
		static SMSSettings()
		{
			if (Instance.UpdateRequired)
			{
				Instance.Upgrade();
				Instance.UpdateRequired = false;
			}
		}

		private SMSSettings()
		{
		}

		public ISMSInfo SMSInfo
		{
			get { return SMSInfo2; }
		}

		public void AddUser(string smsServiceName, IUser user)
		{
			Users.Value.Add(smsServiceName, (User) user);
		}

		public IUser GetUser(string smsServiceName)
		{
			return !Users.Value.ContainsKey(smsServiceName) ? null : Users.Value[smsServiceName];
		}

		/// <summary>
		/// Gets the instance.
		/// As Settings.Default is generated by the tool, instead of it this is used.
		/// </summary>
		[Export(typeof (ISMSSettings))]
		public static SMSSettings Instance
		{
			get { return defaultInstance; }
		}
	}
}